/*	This file is part of LSAC.

	LSAC is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	LSAC is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with LSAC.  If not, see <http://www.gnu.org/licenses/>.

	Copyright (c) 2010 LEPESME "Jiboo" Jean-Baptiste
*/

#include "cSemContext.h"

void cSemContext::declareFunction(cFunction* pFunc)
{
	this->dFunctions.push_back(pFunc);
}

void cSemContext::declareVar(cInstDecl* pDecl)
{
	this->dVars.push_back(pDecl);
}

cInstDecl *cSemContext::varExists(string &pName)
{
	list<cInstDecl*>::iterator lIterator = this->dVars.begin();
	for(; lIterator != this->dVars.end(); lIterator++)
	{
		if((*lIterator)->dLValue == pName) return (*lIterator);
	}
	return NULL;
}

cFunction *cSemContext::funcExists(string &pName)
{
	list<cFunction*>::iterator lIterator = this->dFunctions.begin();
	for(; lIterator != this->dFunctions.end(); lIterator++)
	{
		if((*lIterator)->dName == pName) return (*lIterator);
	}
	return NULL;
}

void cSemContext::removeLocals(cBlock *pBlock)
{
	list<cInstDecl*>::iterator lIterator = this->dVars.begin();
	for(; lIterator != this->dVars.end(); lIterator++)
	{
		if((*lIterator)->dParent == pBlock) lIterator = this->dVars.erase(lIterator);
	}
}

